# 菜单API测试脚本
$baseUrl = "http://localhost:5095"

Write-Host "=== 菜单API功能测试 ===" -ForegroundColor Green

# 测试1: 获取所有菜单
Write-Host "`n1. 获取所有菜单" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/menu" -Method GET -ContentType "application/json"
    Write-Host "成功获取菜单列表" -ForegroundColor Green
    Write-Host "菜单树节点数: $($response.data.menuTree.Count)" -ForegroundColor Green
    Write-Host "总数: $($response.data.totalCount)" -ForegroundColor Green
    
    # 显示菜单详情
    foreach ($menu in $response.data.menuTree) {
        Write-Host "  - $($menu.menuname) ($($menu.menuPath))" -ForegroundColor Cyan
    }
} catch {
    Write-Host "获取菜单列表失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试2: 按菜单名称搜索
Write-Host "`n2. 按菜单名称搜索 (包含'管理')" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/menu?Menuname=管理" -Method GET -ContentType "application/json"
    Write-Host "搜索成功，找到菜单数: $($response.data.totalCount)" -ForegroundColor Green
    foreach ($menu in $response.data.menuTree) {
        Write-Host "  - $($menu.menuname)" -ForegroundColor Cyan
    }
} catch {
    Write-Host "按名称搜索失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试3: 按菜单路径搜索
Write-Host "`n3. 按菜单路径搜索 (包含'/system')" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/menu?MenuPath=/system" -Method GET -ContentType "application/json"
    Write-Host "搜索成功，找到菜单数: $($response.data.totalCount)" -ForegroundColor Green
    foreach ($menu in $response.data.menuTree) {
        Write-Host "  - $($menu.menuname) ($($menu.menuPath))" -ForegroundColor Cyan
    }
} catch {
    Write-Host "按路径搜索失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试4: 获取菜单树
Write-Host "`n4. 获取菜单树" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/menu/tree" -Method GET -ContentType "application/json"
    Write-Host "获取菜单树成功，根节点数: $($response.data.Count)" -ForegroundColor Green
    foreach ($menu in $response.data) {
        Write-Host "  - $($menu.menuname) (子菜单数: $($menu.children.Count))" -ForegroundColor Cyan
    }
} catch {
    Write-Host "获取菜单树失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试5: 分页查询
Write-Host "`n5. 分页查询 (第1页，每页2条)" -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "$baseUrl/api/menu?pageIndex=1&pageSize=2" -Method GET -ContentType "application/json"
    Write-Host "分页查询成功，总数: $($response.data.totalCount), 当前页菜单数: $($response.data.menuTree.Count)" -ForegroundColor Green
} catch {
    Write-Host "分页查询失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n=== 菜单API功能测试完成 ===" -ForegroundColor Green 